package com.wzh.yebServe.controller;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.wzh.yebServe.pojo.Employee;
import com.wzh.yebServe.pojo.RespPageBean;
import com.wzh.yebServe.pojo.ResultBean;
import com.wzh.yebServe.pojo.Salary;
import com.wzh.yebServe.service.IEmployeeService;
import com.wzh.yebServe.service.ISalaryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author wzh
 * @create 2022/11/22 14:59
 * @Description:
 */
@Api(tags = "工资套账接口")
@RestController
@RequestMapping("/salary/sobcfg")
public class SalarySobCfgController {
    @Autowired
    private ISalaryService iSalaryService;

    @Autowired
    private IEmployeeService iEmployeeService;


    @ApiOperation(value = "获取所有工资套账")
    @GetMapping("/salaries")
    public List<Salary> getAllSalary(){
        return iSalaryService.list();
    }


@ApiOperation(value = "查询员工和工资套账")
    @GetMapping("/")
public RespPageBean getEmployeeWithSalary(@RequestParam(defaultValue = "1") Integer currentPage, @RequestParam(defaultValue = "10") Integer size){
        return iEmployeeService.getEmployeeWithSalary(currentPage,size);

}

    @ApiOperation(value = "更新员工套账")
    @PutMapping("/")
    public ResultBean updateEmployeeSalary(Integer eid,Integer sid){
        if (iEmployeeService.update(new UpdateWrapper<Employee>().set("salaryId",sid).eq("id",eid))){
            return ResultBean.success("更新成功");
        }
        return ResultBean.error("更新失败");
    }




}
